from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from .database import init_db
from .models import account
from .routers import account as account_router
from .routers import environment as environment_router
from .routers import browser as browser_router
import os
from pathlib import Path

# 创建数据库表
init_db()

app = FastAPI(title="微信公众号矩阵管理系统")

# 获取项目根目录
BASE_DIR = Path(__file__).resolve().parent.parent

# 挂载静态文件
app.mount("/static", StaticFiles(directory=str(BASE_DIR / "static")), name="static")

# 模板配置
templates = Jinja2Templates(directory="app/templates")

# 注册路由
app.include_router(account_router.router)
app.include_router(environment_router.router)
app.include_router(browser_router.router)

@app.get("/")
async def root(request: Request):
    return templates.TemplateResponse(
        "index.html",
        {"request": request, "title": "首页"}
    ) 